<template>
  <div class="container">
    <div class="login-wrapper">
      <div class="header">图书管理系统</div>
      <div class="form-wrapper">
        <!-- 登录 -->
        <el-form ref="loginForm" :model="loginForm">
          <el-form-item>
            <el-input
              v-model="loginForm.username"
              class="input-item"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="loginForm.password"
              type="password"
              class="input-item"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit" class="btn"
              >登录</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { getLoginAPI } from "@/api";
import { mapMutations } from "vuex";
export default {
  name: "Login",
  data() {
    return {
      loginForm: {
        username: "root",
        password: "admin123",
      },
      regForm: {
        username: "root",
        password: "admin123",
        reword: "admin123",
      },
    };
  },
  methods: {
    ...mapMutations(["UPDATETOKEN"]),
    onSubmit(e) {
      console.log(e);
      getLoginAPI().then((res) => {
        console.log(res.data.token);
        localStorage.setItem("token", res.data.token);
        this.UPDATETOKEN(res.data.token);
        console.log(this.$store);
        console.log(this.$router);
        this.$router.push("/");
      });
    },
    loginBtn() {
      this.title = "登录";
      this.isShow = true;
    },
    regBtn() {
      this.title = "注册";
      this.isShow = false;
    },
  },
};
</script>

<style scoped>
.container {
  height: 100%;
  /* background-image: linear-gradient(to right, #fbc2eb, #a6c1ee); */
  /* background-image: linear-gradient(to right, #3c9eda, #2f6fef); */
  background-color: #394b58;
}
.login-wrapper {
  background-color: #fff;
  width: 358px;
  height: 588px;
  border-radius: 15px;
  padding: 0 50px;
  position: relative;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.header {
  font-size: 38px;
  font-weight: bold;
  text-align: center;
  line-height: 200px;
}
.input-item {
  display: block;
  width: 100%;
  padding: 10px;
  box-sizing: border-box;
  /* border-bottom: 1px solid rgb(128, 125, 125); */
  font-size: 15px;
  outline: none;
}
.el-input__inner {
  border: 0;
}
.input-item:placeholder {
  text-transform: uppercase;
}
.btn {
  width: 100%;
  /* background-image: linear-gradient(to right, #a6c1ee, #fbc2eb); */
  background-image: linear-gradient(to right, #2fb2ef, #1ddbec);
  color: #fff;
  border: 0;
  margin-top: 50px;
}
</style>
